How to Develop an Online Shopping Cart (Part Three)
Table of Contents
Checkout.cfm
In the checkout page, I provide the user with details of what she has in her cart, what the order total is, and I present her with an order form. Open checkout.cfm in the Code view. The code between lines 52 and 71 of the checkout.cfm page shows what's in the cart.
<cfset ordertotal = 0> <cfloop from="1" to="#ArrayLen(Session.Cart.ItemID)#" index="ThisItem"> <cfquery name="geItem" datasource="DevNetExample"> SELECT itemPrice,itemID,itemName FROM Items WHERE itemID = #Session.Cart.ItemID[ThisItem]# </cfquery> <cfset total = 0> <cfset total = total + (geItem.itemPrice * Session.Cart.Qty[ThisItem]) > <cfoutput> <span class="txt-bold">ItemID: #Session.Cart.ItemID[ThisItem]#| Quantity: #Session.Cart.Qty[ThisItem]# | Total: #LSCurrencyFormat(total,'local')#<BR> </span></cfoutput><span class="txt-bold"> </span> <cfset ordertotal = ordertotal + total> </cfloop></td> <td valign="top"> <span class="txt-bold"><cfoutput>#ordertotal#</cfoutput></span><br>
Here I also create the final cart total that the app will be pass to the orders table in the database. In the form that follows this code on line154, you'll find a hidden form field I use to pass the order total to the Process Order/Confirmation page.